﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace DotNetDetour
{
    class Socket
    {
        static GClient client = new GClient();
        static Byte[] buffer = null;

        static Socket(){
            //client.send("Client Inited");
        }

        public static bool send(String a,String b) {
            return client.send(a,b);
        }

        public static void send(String a)
        {
            client.send(a);
        }

        public static void send(byte[] bs)
        {
            client.send(bs);
        }

        public static string send_Ret(string a,string b) {
            return client.send_Ret(a,b);
        }

        public static string recv(String a, int b) {
            return client.recv(a,b);
        }

        public static void listen() {
            while (true) {
                try
                {
                    int len = 0;
                    buffer = new byte[1024];
                    System.Net.Sockets.Socket socket = client.getSocket();
                    String result = "";
                    while ((len = socket.Receive(buffer, SocketFlags.None)) > 0)
                    {
                        result = Encoding.UTF8.GetString(buffer);
                        client.send(result);
                        Thread.Sleep(50);
                    }
                    Thread.Sleep(1000);
                }
                catch {
                }
            }
        }

        public static String toString() { return ""; }

        internal static void send(Process process)
        {
            throw new NotImplementedException();
        }
    }
}
